package com.freedy.concurrent.OptimisticLock;


import sun.misc.Unsafe;

import java.lang.reflect.Field;


/**
 * @author Freedy
 * @date 2021/4/24 15:10
 */
public class UnsafeGetter {

    public static Unsafe getUnsafe() {
        Unsafe unsafe=null;
        try {
            Field unsafeField = Unsafe.class.getDeclaredField("theUnsafe");
            unsafeField.setAccessible(true);
            unsafe = (Unsafe)unsafeField.get(null);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return unsafe;
    }
}
